import json
import time

from GlobalValues import globalVal
from util import ReadConfig
from camera import PointCouldSocket


def getParamNames():
    f = open('pushConfig.txt', 'r', encoding='utf-8')
    data = json.load(f)
    return data


def modifyParams(args):
    f = open('pushConfig.txt', 'r', encoding='utf-8')
    data = json.load(f)
    print(args)
    if "rtmp|推流地址" in args:
        data["rtmp|推流地址"] = args.get("rtmp|推流地址")
    if "resolution|分辨率" in args:
        data["resolution|分辨率"] = args.get("resolution|分辨率")
    if "frameRate|频率" in args:
        data["frameRate|频率"] = args.get("frameRate|频率")
    # print(json.dumps(data, sort_keys=True, indent=4, ensure_ascii=False))
    with open("pushConfig.txt", "w", encoding='utf-8') as f:
        f.write(json.dumps(data, sort_keys=True, indent=4, ensure_ascii=False))
    ReadConfig.readConfig()
    globalVal.camera_conf = True

    return "1"


def openPointCould():
    try:
        print("点云开始")
        globalVal.pointCould_control = True
        globalVal.pointCould_future = globalVal.pool.submit(PointCouldSocket.pointCould_socket)
        return "1"
    except Exception as e:
        print(e)
        return "0"


def closePointCould():
    try:
        print('点云关闭')
        globalVal.pointCould_control = False
        return '1'
    except Exception as e:
        print(e)
        return '0'
